RANDOMIZE TIMER DIM vectors(10,10):DIM solutionmatrix(10,10):MOUSE ON REM Read Transformation Vectors FOR col=0 TO 9 FOR row=0 TO 9 READ vectors(row,col) NEXT row NEXT col REM Read Winning Vector FOR row=0 TO 9 READ winningvector(row) NEXT row REM Read Solution Matrix FOR col=0 TO 9 FOR row=0 TO 9 READ solutionmatrix(row,col) NEXT row NEXT col REM Read block coordinates for paint function FOR row=0 TO 9 READ bx(row),by(row) NEXT row REM Read voice data FOR v=0 TO 8 READ how%(v) NEXT v start: CLS REM Iniatialization FOR i=0 TO 9:gamevector(i)=0:NEXT i attempts=0 REM Generate random starting pattern and display it. FOR i=1 TO 9 initialpattern = INT(RND*512) IF initialpattern/2-INT(initialpattern/2)=0 THEN gamevector(i)=1 ON i GOSUB b1,b2,b3,b4,b5,b6,b7,b8,b9 END IF IF gamevector(i)<>1 THEN gamevector(i)=0 ON i GOSUB eb1,eb2,eb3,eb4,eb5,eb6,eb7,eb8,eb9 END IF NEXT i REM Partition Window LINE (15,160)-(615,160):LINE (615,160)-(615,165) LINE (615,165)-(15,165):LINE (15,165)-(15,160) PAINT (20,163),2,1 LOCATE 22,5 PRINT " Click on the square with which you wish to change the pattern" REM Query the mouse query: M0=MOUSE(0) IF M0=1 THEN GOSUB WhereIsIt GOTO query WhereIsIt: M1=MOUSE(1):M2=MOUSE(2) IF M1>119 AND M1<201 AND M2>14 AND M2<46 THEN block = 1 IF M1>279 AND M1<361 AND M2>14 AND M2<46 THEN block = 2 IF M1>439 AND M1<521 AND M2>14 AND M2<46 THEN block = 3 IF M1>119 AND M1<201 AND M2>64 AND M2<96 THEN block = 4 IF M1>279 AND M1<361 AND M2>64 AND M2<96 THEN block = 5 IF M1>439 AND M1<521 AND M2>64 AND M2<96 THEN block = 6 IF M1>119 AND M1<201 AND M2>114 AND M2<146 THEN block = 7 IF M1>279 AND M1<361 AND M2>114 AND M2<146 THEN block = 8 IF M1>439 AND M1<521 AND M2>114 AND M2<146 THEN block = 9 IF M1>14 AND M1<79 AND M2>143 AND M2<153 THEN block = 10 REM Check if mouse was clicked in a game block IF block=0 THEN BEEP:WINDOW 2,"ERROR",(190,95)-(445,115),2,-1 COLOR 3,0 PRINT" Click inside a block please..." FOR i=1 TO 3500:NEXT i WINDOW CLOSE 2 RETURN END IF REM Check if mouse was clicked in the solve it block IF block=10 THEN FOR row=1 TO 9 tempvector(row)=gamevector(row) XOR winningvector(row) NEXT row FOR row=1 TO 9 FOR col=1 TO 9 vector(col)=solutionmatrix(row,col)*tempvector(col) NEXT col FOR i=1 TO 8 vector(i+1)=vector(i) XOR vector(i+1) NEXT i solutionvector(row)=vector(i) NEXT row WINDOW 2,"Solution",(220,95)-(420,103),2,-1 COLOR 3,0 FOR row=1 TO 9 IF solutionvector(row)=1 THEN PRINT row; NEXT row FOR i=1 TO 5000:NEXT i:WINDOW CLOSE 2 block=0:RETURN END IF REM Transform Pattern FOR row=1 TO 9 gamevector(row)=gamevector(row) XOR vectors(row,block) NEXT row REM Print the number of attempts so far CLS:LOCATE 1,34:COLOR 3,1 attempts=attempts+1:PRINT" Attempts:"attempts COLOR 1,0 FOR i=1 TO 9 IF gamevector(i)=1 THEN ON i GOSUB b1,b2,b3,b4,b5,b6,b7,b8,b9 IF gamevector(i)=0 THEN ON i GOSUB eb1,eb2,eb3,eb4,eb5,eb6,eb7,eb8,eb9 NEXT i REM Partition Window LINE (15,160)-(615,160):LINE (615,160)-(615,165) LINE (615,165)-(15,165):LINE (15,165)-(15,160) PAINT (20,163),2,1 LOCATE 22,5 PRINT " Click on the square with which you wish to change the pattern" REM Set block to 0 to indicate no block selected block=0 REM Display solution help block COLOR 3,1:LOCATE 19,3:PRINT" Solve? ":COLOR 1,0 REM Check for success FOR row=1 TO 9 IF gamevector(row)=winningvector(row) THEN win=1 :ELSE RETURN NEXT row COLOR 3,0 FOR i=1 TO 9 ON i GOSUB eb1,eb2,eb3,eb4,eb5,eb6,eb7,eb8,eb9 IF i<>5 THEN PAINT (bx(i),by(i)),2,3 NEXT i SAY TRANSLATE$ ("Congratulations you have solved Magic Square"),how% SAY TRANSLATE$ ("If you would like to try again press the Y key"),how% COLOR 1,0 PlayAgain: a$=INKEY$ IF a$="y" THEN start :ELSE IF a$="n" THEN END GOTO PlayAgain REM Fill in blocks b1: AREA (120,15):AREA (200,15):AREA (200,45):AREA (120,45):AREAFILL RETURN b2: AREA (280,15):AREA (360,15):AREA (360,45):AREA (280,45):AREAFILL RETURN b3: AREA (440,15):AREA (520,15):AREA (520,45):AREA (440,45):AREAFILL RETURN b4: AREA (120,65):AREA (200,65):AREA (200,95):AREA (120,95):AREAFILL RETURN b5: AREA (280,65):AREA (360,65):AREA (360,95):AREA (280,95):AREAFILL RETURN b6: AREA (440,65):AREA (520,65):AREA (520,95):AREA (440,95):AREAFILL RETURN b7: AREA (120,115):AREA (200,115):AREA (200,145):AREA (120,145):AREAFILL RETURN b8: AREA (280,115):AREA (360,115):AREA (360,145):AREA (280,145):AREAFILL RETURN b9: AREA (440,115):AREA (520,115):AREA (520,145):AREA (440,145):AREAFILL RETURN REM Draw border around empty blocks eb1: LINE (120,15)-(200,15):LINE (200,15)-(200,45) LINE (200,45)-(120,45):LINE (120,45)-(120,15) RETURN eb2: LINE (280,15)-(360,15):LINE (360,15)-(360,45) LINE (360,45)-(280,45):LINE (280,45)-(280,15) RETURN eb3: LINE (440,15)-(520,15):LINE (520,15)-(520,45) LINE (520,45)-(440,45):LINE (440,45)-(440,15) RETURN eb4: LINE (120,65)-(200,65):LINE (200,65)-(200,95) LINE (200,95)-(120,95):LINE (120,95)-(120,65) RETURN eb5: LINE (280,65)-(360,65):LINE (360,65)-(360,95) LINE (360,95)-(280,95):LINE (280,95)-(280,65) RETURN eb6: LINE (440,65)-(520,65):LINE (520,65)-(520,95) LINE (520,95)-(440,95):LINE (440,95)-(440,65) RETURN eb7: LINE (120,115)-(200,115):LINE (200,115)-(200,145) LINE (200,145)-(120,145):LINE (120,145)-(120,115) RETURN eb8: LINE (280,115)-(360,115):LINE (360,115)-(360,145) LINE (360,145)-(280,145):LINE (280,145)-(280,115) RETURN eb9: LINE (440,115)-(520,115):LINE (520,115)-(520,145) LINE (520,145)-(440,145):LINE (440,145)-(440,115) RETURN REM Transformation Vectors DATA 0,0,0,0,0,0,0,0,0,0 DATA 0,1,1,0,1,1,0,0,0,0 DATA 0,1,1,1,0,0,0,0,0,0 DATA 0,0,1,1,0,1,1,0,0,0 DATA 0,1,0,0,1,0,0,1,0,0 DATA 0,0,1,0,1,1,1,0,1,0 DATA 0,0,0,1,0,0,1,0,0,1 DATA 0,0,0,0,1,1,0,1,1,0 DATA 0,0,0,0,0,0,0,1,1,1 DATA 0,0,0,0,0,1,1,0,1,1 REM Winning Vector DATA 0,1,1,1,1,0,1,1,1,1 REM Solution Matrix DATA 0,0,0,0,0,0,0,0,0,0 DATA 0,1,1,1,1,1,0,1,0,0 DATA 0,0,1,0,1,0,1,1,0,1 DATA 0,1,1,1,0,1,1,0,0,1 DATA 0,0,1,1,1,0,0,0,1,1 DATA 0,0,1,0,1,1,1,0,1,0 DATA 0,1,1,0,0,0,1,1,1,0 DATA 0,1,0,0,1,1,0,1,1,1 DATA 0,1,0,1,1,0,1,0,1,0 DATA 0,0,0,1,0,1,1,1,1,1 REM Coordinate Data DATA 0,0 DATA 160,30,320,30,460,30 DATA 160,80,320,80,460,80 DATA 160,130,320,130,460,130 REM Voice Data DATA 240,0,170,1,21000,64,10,0,0